﻿CREATE procedure dbo.GetMyPreferredMenus
(
		@UserID int,
		@MenuID int
	)

AS
	SET NOCOUNT ON 
	

	SELECT     dbo.PreferredTakeoutMenu.Id, dbo.PreferredTakeoutMenu.Name, dbo.PreferredTakeoutMenu.UserID, dbo.PreferredTakeoutMenu.Instructions
	FROM         dbo.PreferredTakeoutMenu INNER JOIN
	                      dbo.PreferredTakeoutMenuItems ON dbo.PreferredTakeoutMenu.Id = dbo.PreferredTakeoutMenuItems.PreferredTakeoutMenuId INNER JOIN
	                      dbo.MenuItems ON dbo.PreferredTakeoutMenuItems.MenuItemID = dbo.MenuItems.Id
	WHERE     (dbo.PreferredTakeoutMenu.UserID = @UserID) AND (dbo.MenuItems.MenusId = @MenuID)

SELECT     dbo.PreferredTakeoutMenuItems.Id, dbo.PreferredTakeoutMenuItems.MenuItemID, dbo.PreferredTakeoutMenuItems.PreferredTakeoutMenuId, 
                      dbo.PreferredTakeoutMenuItems.Quantity, dbo.MenuItems.MenusId
FROM         dbo.PreferredTakeoutMenu INNER JOIN
                     dbo.PreferredTakeoutMenuItems ON dbo.PreferredTakeoutMenu.Id = dbo.PreferredTakeoutMenuItems.PreferredTakeoutMenuId INNER JOIN
                      dbo.MenuItems ON dbo.PreferredTakeoutMenuItems.MenuItemID = dbo.MenuItems.Id
WHERE     (dbo.PreferredTakeoutMenu.UserID = @UserID) AND (dbo.MenuItems.MenusId = @MenuID)
	
SELECT     dbo.MenuItems.Id, dbo.MenuItems.MenusId, dbo.MenuItems.Description, dbo.MenuItems.Price, dbo.MenuItems.PrepTimeMinutes
FROM         dbo.MenuItems INNER JOIN
                      dbo.PreferredTakeoutMenuItems ON dbo.MenuItems.Id = dbo.PreferredTakeoutMenuItems.MenuItemID INNER JOIN
                      dbo.PreferredTakeoutMenu ON dbo.PreferredTakeoutMenuItems.PreferredTakeoutMenuId = dbo.PreferredTakeoutMenu.Id
WHERE     (dbo.PreferredTakeoutMenu.UserID = @UserID) AND (dbo.MenuItems.MenusId = @MenuID)
	
SELECT     dbo.Menus.Id, dbo.Menus.CategoryId, dbo.Menus.Name, dbo.Menus.Address, dbo.Menus.City, dbo.Menus.State, dbo.Menus.Zipcode, dbo.Menus.TaxRate, 
                      dbo.PreferredTakeoutMenu.UserID
FROM         dbo.MenuItems INNER JOIN
                      dbo.Menus ON dbo.MenuItems.MenusId = dbo.Menus.Id INNER JOIN
                      dbo.PreferredTakeoutMenuItems ON dbo.MenuItems.Id = dbo.PreferredTakeoutMenuItems.MenuItemID INNER JOIN
                      dbo.PreferredTakeoutMenu ON dbo.PreferredTakeoutMenuItems.PreferredTakeoutMenuId = dbo.PreferredTakeoutMenu.Id
WHERE     (dbo.Menus.Id = @MenuID) AND (dbo.PreferredTakeoutMenu.UserID = @UserID)	

SELECT     dbo.Category.Id, dbo.Category.Name, dbo.Category.Description
FROM         dbo.MenuItems INNER JOIN
                      dbo.Menus ON dbo.MenuItems.MenusId = dbo.Menus.Id INNER JOIN
                      dbo.PreferredTakeoutMenuItems ON dbo.MenuItems.Id = dbo.PreferredTakeoutMenuItems.MenuItemID INNER JOIN
                      dbo.PreferredTakeoutMenu ON dbo.PreferredTakeoutMenuItems.PreferredTakeoutMenuId = dbo.PreferredTakeoutMenu.Id INNER JOIN
                      dbo.Category ON dbo.Menus.CategoryId = dbo.Category.Id
WHERE     (dbo.Menus.Id = @MenuID) AND (dbo.PreferredTakeoutMenu.UserID = @UserID)	
	

	
	RETURN


